/*
 * JStock - Free Stock Market Software
 * Copyright (C) 2010 Yan Cheng CHEOK <yccheok@yahoo.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

package org.yccheok.jstock.gui.analysis;

import java.awt.*;


/**
 *
 * @author  yccheok
 */
public class ObjectInspectorJFrame extends javax.swing.JFrame {
    
    /** Creates new form ObjectInspectorJFrame */
    public ObjectInspectorJFrame(Object bean) {
        initComponents();
        
        this.sheet = this.createPropertySheetPanel(bean);
        
        this.setTitle(this.sheet.getBean().getClass().getSimpleName());
        this.getContentPane().add(this.sheet, BorderLayout.CENTER);        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-265)/2, (screenSize.height-317)/2, 265, 317);
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        this.sheet.stopCellEditing();
        // Shall we just dispose the window and ignore returned value from sheet?
        // Or shall we prompt user on his mistake and request him to make
        // correction?
        this.dispose();
    }//GEN-LAST:event_formWindowClosing
       
    private ObjectInspectorJPanel createPropertySheetPanel(Object bean) {    
        final ObjectInspectorJPanel objectInspectorJPanel = new ObjectInspectorJPanel(bean);
        objectInspectorJPanel.setDescriptionVisible(true);
        return objectInspectorJPanel;
    }
    
    public void setBean(Object bean) {
        sheet.setBean(bean);
        this.setTitle(this.sheet.getBean().getClass().getSimpleName());
    }
    
    private final ObjectInspectorJPanel sheet;
            
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    
}
